package com.excellent.mvvm.utils;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.widget.ImageView;

import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.Target;
import com.excellent.mvvm.R;


public class GlideUtils {


    public static final int placeholderSoWhite = R.drawable.icon_video_holdplace2;
    public static final int errorSoWhite = R.drawable.icon_video_holdplace2;

    /*
     *加载图片(默认)
     */
    public static void loadImage(Context context, int rid, ImageView imageView) {
        RequestOptions options = new RequestOptions().centerCrop().placeholder(placeholderSoWhite) //占位图
                .error(errorSoWhite)       //错误图
                // .priority(Priority.HIGH)
                .diskCacheStrategy(DiskCacheStrategy.ALL);
        Glide.with(context).load(rid).apply(options).into(imageView);

    }

    public static void loadGif(Context context, int urlID, ImageView imageView) {
        RequestOptions options = new RequestOptions().placeholder(placeholderSoWhite).error(errorSoWhite);
        Glide.with(context).load(urlID).apply(options).listener(new RequestListener<Drawable>() {
            @Override
            public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
                return false;
            }

            @Override
            public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
                return false;
            }
        }).into(imageView);

    }
}



